"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const vue_1 = require("vue");
const promptApi_1 = require("@/api/promptApi");
const element_plus_1 = require("element-plus");
exports.default = defineComponent({
    name: 'PromptManagementView',
    setup() {
        const promptList = (0, vue_1.ref)([]);
        const selectedIds = (0, vue_1.ref)([]);
        const handleSelectionChange = (selection) => {
            selectedIds.value = selection.map((item) => item.promptId);
        };
        const handleSingleDelete = (id) => __awaiter(this, void 0, void 0, function* () {
            try {
                yield element_plus_1.ElMessageBox.confirm('确定删除该提示词吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                });
                yield (0, promptApi_1.deletePrompts)([id]);
                element_plus_1.ElMessage.success('删除成功');
                fetchPromptList();
            }
            catch (error) {
                console.error('删除失败:', error);
            }
        });
        const handleBatchDelete = () => __awaiter(this, void 0, void 0, function* () {
            if (!selectedIds.value.length) {
                element_plus_1.ElMessage.warning('请选择要删除的提示词');
                return;
            }
            try {
                yield element_plus_1.ElMessageBox.confirm('确定删除选中的提示词吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                });
                yield (0, promptApi_1.deletePrompts)(selectedIds.value);
                element_plus_1.ElMessage.success('删除成功');
                fetchPromptList();
            }
            catch (error) {
                console.error('删除失败:', error);
            }
        });
        const fetchPromptList = () => __awaiter(this, void 0, void 0, function* () {
            try {
                const res = yield (0, promptApi_1.getPromptList)();
                if (res.code === 200 && res.success) {
                    promptList.value = res.data;
                }
            }
            catch (error) {
                console.error('获取提示词列表失败:', error);
            }
        });
        const dialogVisible = (0, vue_1.ref)(false);
        const form = (0, vue_1.reactive)({
            promptId: '',
            promptName: '',
            promptContent: '',
        });
        const handleAdd = () => {
            form.promptId = '';
            form.promptName = '';
            form.promptContent = '';
            dialogVisible.value = true;
        };
        const handleEdit = (row) => {
            form.promptId = row.promptId.toString();
            form.promptName = row.promptName;
            form.promptContent = row.promptContent;
            dialogVisible.value = true;
        };
        const submitForm = () => __awaiter(this, void 0, void 0, function* () {
            if (!form.promptName || !form.promptContent) {
                element_plus_1.ElMessage.error('提示词名称和内容不能为空');
                return;
            }
            try {
                console.log('正在提交表单数据:', form);
                let res;
                if (form.promptId) {
                    res = yield (0, promptApi_1.updatePrompt)(form);
                }
                else {
                    res = yield (0, promptApi_1.addPrompt)(form);
                }
                console.log('接口返回:', res);
                if (res.code === 200 && res.success) {
                    element_plus_1.ElMessage.success(form.promptId ? '修改成功' : '新增成功');
                    dialogVisible.value = false;
                    fetchPromptList();
                    form.promptId = '';
                    form.promptName = '';
                    form.promptContent = '';
                }
                else {
                    element_plus_1.ElMessage.error(res.message || '操作失败');
                }
            }
            catch (error) {
                console.error('操作失败:', error);
                if (error instanceof Error) {
                    element_plus_1.ElMessage.error(error.message || '操作失败');
                }
                else {
                    element_plus_1.ElMessage.error('操作失败');
                }
            }
        });
        fetchPromptList();
        return {
            promptList,
            selectedIds,
            handleSelectionChange,
            handleBatchDelete,
            handleSingleDelete,
            handleAdd,
            handleEdit,
            submitForm,
            dialogVisible,
            form,
        };
    },
});
debugger; /* PartiallyEnd: #3632/script.vue */
const __VLS_ctx = {};
let __VLS_components;
let __VLS_directives;
/** @type {__VLS_StyleScopedClasses['el-table']} */ ;
/** @type {__VLS_StyleScopedClasses['el-table']} */ ;
// CSS variable injection 
// CSS variable injection end 
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(Object.assign({ class: "prompt-management" }));
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(Object.assign({ style: {} }));
const __VLS_0 = {}.ElButton;
/** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
// @ts-ignore
const __VLS_1 = __VLS_asFunctionalComponent(__VLS_0, new __VLS_0(Object.assign({ 'onClick': {} }, { type: "primary" })));
const __VLS_2 = __VLS_1(Object.assign({ 'onClick': {} }, { type: "primary" }), ...__VLS_functionalComponentArgsRest(__VLS_1));
let __VLS_4;
let __VLS_5;
let __VLS_6;
const __VLS_7 = {
    onClick: (__VLS_ctx.handleAdd)
};
__VLS_3.slots.default;
var __VLS_3;
const __VLS_8 = {}.ElDialog;
/** @type {[typeof __VLS_components.ElDialog, typeof __VLS_components.elDialog, typeof __VLS_components.ElDialog, typeof __VLS_components.elDialog, ]} */ ;
// @ts-ignore
const __VLS_9 = __VLS_asFunctionalComponent(__VLS_8, new __VLS_8({
    modelValue: (__VLS_ctx.dialogVisible),
    title: "新增提示词",
    width: "60%",
}));
const __VLS_10 = __VLS_9({
    modelValue: (__VLS_ctx.dialogVisible),
    title: "新增提示词",
    width: "60%",
}, ...__VLS_functionalComponentArgsRest(__VLS_9));
__VLS_11.slots.default;
const __VLS_12 = {}.ElForm;
/** @type {[typeof __VLS_components.ElForm, typeof __VLS_components.elForm, typeof __VLS_components.ElForm, typeof __VLS_components.elForm, ]} */ ;
// @ts-ignore
const __VLS_13 = __VLS_asFunctionalComponent(__VLS_12, new __VLS_12({
    model: (__VLS_ctx.form),
    labelWidth: "100px",
}));
const __VLS_14 = __VLS_13({
    model: (__VLS_ctx.form),
    labelWidth: "100px",
}, ...__VLS_functionalComponentArgsRest(__VLS_13));
__VLS_15.slots.default;
const __VLS_16 = {}.ElFormItem;
/** @type {[typeof __VLS_components.ElFormItem, typeof __VLS_components.elFormItem, typeof __VLS_components.ElFormItem, typeof __VLS_components.elFormItem, ]} */ ;
// @ts-ignore
const __VLS_17 = __VLS_asFunctionalComponent(__VLS_16, new __VLS_16({
    label: "提示词名称",
}));
const __VLS_18 = __VLS_17({
    label: "提示词名称",
}, ...__VLS_functionalComponentArgsRest(__VLS_17));
__VLS_19.slots.default;
const __VLS_20 = {}.ElInput;
/** @type {[typeof __VLS_components.ElInput, typeof __VLS_components.elInput, ]} */ ;
// @ts-ignore
const __VLS_21 = __VLS_asFunctionalComponent(__VLS_20, new __VLS_20({
    modelValue: (__VLS_ctx.form.promptName),
    placeholder: "请输入提示词名称",
}));
const __VLS_22 = __VLS_21({
    modelValue: (__VLS_ctx.form.promptName),
    placeholder: "请输入提示词名称",
}, ...__VLS_functionalComponentArgsRest(__VLS_21));
var __VLS_19;
const __VLS_24 = {}.ElFormItem;
/** @type {[typeof __VLS_components.ElFormItem, typeof __VLS_components.elFormItem, typeof __VLS_components.ElFormItem, typeof __VLS_components.elFormItem, ]} */ ;
// @ts-ignore
const __VLS_25 = __VLS_asFunctionalComponent(__VLS_24, new __VLS_24({
    label: "提示词内容",
}));
const __VLS_26 = __VLS_25({
    label: "提示词内容",
}, ...__VLS_functionalComponentArgsRest(__VLS_25));
__VLS_27.slots.default;
const __VLS_28 = {}.ElInput;
/** @type {[typeof __VLS_components.ElInput, typeof __VLS_components.elInput, ]} */ ;
// @ts-ignore
const __VLS_29 = __VLS_asFunctionalComponent(__VLS_28, new __VLS_28({
    modelValue: (__VLS_ctx.form.promptContent),
    type: "textarea",
    rows: (8),
    placeholder: "请输入提示词内容",
}));
const __VLS_30 = __VLS_29({
    modelValue: (__VLS_ctx.form.promptContent),
    type: "textarea",
    rows: (8),
    placeholder: "请输入提示词内容",
}, ...__VLS_functionalComponentArgsRest(__VLS_29));
var __VLS_27;
var __VLS_15;
{
    const { footer: __VLS_thisSlot } = __VLS_11.slots;
    const __VLS_32 = {}.ElButton;
    /** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
    // @ts-ignore
    const __VLS_33 = __VLS_asFunctionalComponent(__VLS_32, new __VLS_32(Object.assign({ 'onClick': {} })));
    const __VLS_34 = __VLS_33(Object.assign({ 'onClick': {} }), ...__VLS_functionalComponentArgsRest(__VLS_33));
    let __VLS_36;
    let __VLS_37;
    let __VLS_38;
    const __VLS_39 = {
        onClick: (...[$event]) => {
            __VLS_ctx.dialogVisible = false;
        }
    };
    __VLS_35.slots.default;
    var __VLS_35;
    const __VLS_40 = {}.ElButton;
    /** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
    // @ts-ignore
    const __VLS_41 = __VLS_asFunctionalComponent(__VLS_40, new __VLS_40(Object.assign({ 'onClick': {} }, { type: "primary" })));
    const __VLS_42 = __VLS_41(Object.assign({ 'onClick': {} }, { type: "primary" }), ...__VLS_functionalComponentArgsRest(__VLS_41));
    let __VLS_44;
    let __VLS_45;
    let __VLS_46;
    const __VLS_47 = {
        onClick: (__VLS_ctx.submitForm)
    };
    __VLS_43.slots.default;
    var __VLS_43;
}
var __VLS_11;
const __VLS_48 = {}.ElButton;
/** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
// @ts-ignore
const __VLS_49 = __VLS_asFunctionalComponent(__VLS_48, new __VLS_48(Object.assign(Object.assign({ 'onClick': {} }, { type: "danger", disabled: (__VLS_ctx.selectedIds.length === 0) }), { style: {} })));
const __VLS_50 = __VLS_49(Object.assign(Object.assign({ 'onClick': {} }, { type: "danger", disabled: (__VLS_ctx.selectedIds.length === 0) }), { style: {} }), ...__VLS_functionalComponentArgsRest(__VLS_49));
let __VLS_52;
let __VLS_53;
let __VLS_54;
const __VLS_55 = {
    onClick: (__VLS_ctx.handleBatchDelete)
};
__VLS_51.slots.default;
var __VLS_51;
const __VLS_56 = {}.ElTable;
/** @type {[typeof __VLS_components.ElTable, typeof __VLS_components.elTable, typeof __VLS_components.ElTable, typeof __VLS_components.elTable, ]} */ ;
// @ts-ignore
const __VLS_57 = __VLS_asFunctionalComponent(__VLS_56, new __VLS_56(Object.assign(Object.assign({ 'onSelectionChange': {} }, { data: (__VLS_ctx.promptList) }), { style: {} })));
const __VLS_58 = __VLS_57(Object.assign(Object.assign({ 'onSelectionChange': {} }, { data: (__VLS_ctx.promptList) }), { style: {} }), ...__VLS_functionalComponentArgsRest(__VLS_57));
let __VLS_60;
let __VLS_61;
let __VLS_62;
const __VLS_63 = {
    onSelectionChange: (__VLS_ctx.handleSelectionChange)
};
__VLS_59.slots.default;
const __VLS_64 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_65 = __VLS_asFunctionalComponent(__VLS_64, new __VLS_64({
    type: "selection",
    width: "55",
}));
const __VLS_66 = __VLS_65({
    type: "selection",
    width: "55",
}, ...__VLS_functionalComponentArgsRest(__VLS_65));
const __VLS_68 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_69 = __VLS_asFunctionalComponent(__VLS_68, new __VLS_68({
    prop: "promptId",
    label: "ID",
    width: "80",
}));
const __VLS_70 = __VLS_69({
    prop: "promptId",
    label: "ID",
    width: "80",
}, ...__VLS_functionalComponentArgsRest(__VLS_69));
const __VLS_72 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_73 = __VLS_asFunctionalComponent(__VLS_72, new __VLS_72({
    prop: "promptName",
    label: "提示词名称",
}));
const __VLS_74 = __VLS_73({
    prop: "promptName",
    label: "提示词名称",
}, ...__VLS_functionalComponentArgsRest(__VLS_73));
const __VLS_76 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_77 = __VLS_asFunctionalComponent(__VLS_76, new __VLS_76({
    prop: "promptContent",
    label: "提示词内容",
}));
const __VLS_78 = __VLS_77({
    prop: "promptContent",
    label: "提示词内容",
}, ...__VLS_functionalComponentArgsRest(__VLS_77));
__VLS_79.slots.default;
{
    const { default: __VLS_thisSlot } = __VLS_79.slots;
    const [scope] = __VLS_getSlotParams(__VLS_thisSlot);
    const __VLS_80 = {}.ElTooltip;
    /** @type {[typeof __VLS_components.ElTooltip, typeof __VLS_components.elTooltip, typeof __VLS_components.ElTooltip, typeof __VLS_components.elTooltip, ]} */ ;
    // @ts-ignore
    const __VLS_81 = __VLS_asFunctionalComponent(__VLS_80, new __VLS_80({
        effect: "dark",
        content: (scope.row.promptContent),
        placement: "top",
        popperClass: "no-max-width",
    }));
    const __VLS_82 = __VLS_81({
        effect: "dark",
        content: (scope.row.promptContent),
        placement: "top",
        popperClass: "no-max-width",
    }, ...__VLS_functionalComponentArgsRest(__VLS_81));
    __VLS_83.slots.default;
    __VLS_asFunctionalElement(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({});
    (scope.row.promptContent.length > 20
        ? scope.row.promptContent.substring(0, 20) + '...'
        : scope.row.promptContent);
    var __VLS_83;
}
var __VLS_79;
const __VLS_84 = {}.ElTableColumn;
/** @type {[typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, typeof __VLS_components.ElTableColumn, typeof __VLS_components.elTableColumn, ]} */ ;
// @ts-ignore
const __VLS_85 = __VLS_asFunctionalComponent(__VLS_84, new __VLS_84({
    label: "操作",
    width: "180",
}));
const __VLS_86 = __VLS_85({
    label: "操作",
    width: "180",
}, ...__VLS_functionalComponentArgsRest(__VLS_85));
__VLS_87.slots.default;
{
    const { default: __VLS_thisSlot } = __VLS_87.slots;
    const [scope] = __VLS_getSlotParams(__VLS_thisSlot);
    const __VLS_88 = {}.ElButton;
    /** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
    // @ts-ignore
    const __VLS_89 = __VLS_asFunctionalComponent(__VLS_88, new __VLS_88(Object.assign({ 'onClick': {} }, { link: true, type: "primary" })));
    const __VLS_90 = __VLS_89(Object.assign({ 'onClick': {} }, { link: true, type: "primary" }), ...__VLS_functionalComponentArgsRest(__VLS_89));
    let __VLS_92;
    let __VLS_93;
    let __VLS_94;
    const __VLS_95 = {
        onClick: (...[$event]) => {
            __VLS_ctx.handleEdit(scope.row);
        }
    };
    __VLS_91.slots.default;
    var __VLS_91;
    const __VLS_96 = {}.ElButton;
    /** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
    // @ts-ignore
    const __VLS_97 = __VLS_asFunctionalComponent(__VLS_96, new __VLS_96(Object.assign({ 'onClick': {} }, { link: true, type: "danger" })));
    const __VLS_98 = __VLS_97(Object.assign({ 'onClick': {} }, { link: true, type: "danger" }), ...__VLS_functionalComponentArgsRest(__VLS_97));
    let __VLS_100;
    let __VLS_101;
    let __VLS_102;
    const __VLS_103 = {
        onClick: (...[$event]) => {
            __VLS_ctx.handleSingleDelete(scope.row.promptId);
        }
    };
    __VLS_99.slots.default;
    var __VLS_99;
}
var __VLS_87;
var __VLS_59;
/** @type {__VLS_StyleScopedClasses['prompt-management']} */ ;
var __VLS_dollars;
let __VLS_self;
